package com.src.xyzk_personal.util;

import android.annotation.SuppressLint;
import android.content.Context;

import com.src.xyzk_personal.config.Common;

/**
 * 配置文件加载类
 * created by sjx on 2024/04/16
 */
public class ConfigFileLoadUtil {

    @SuppressLint("StaticFieldLeak")
    private static Context mContext; //上下文环境

    @SuppressLint("StaticFieldLeak")
    private static ConfigFileLoadUtil instance;

    static String dirDtc = null;
    static String stepFilePath = null;
    static String language;

    public static ConfigFileLoadUtil getInstance(Context context) {
        mContext = context;
        if (instance == null) {
            instance = new ConfigFileLoadUtil();
        }
        language = SharedPreferencesUtil.getString(mContext, SharedPreferencesUtil.LANGUAGE, "en");
        return instance;
    }

    /**
     * 设置故障码文件路径
     * @param carType 车辆类型 -以此确定配置文件中故障码目录名
     * @return 故障码文件路径
     */
    public static String getDirDtc(String carType) {
        switch (language) {
            case "en": {
                dirDtc = Common.Dir + Common.GuestName + "/" + carType + "/" + "dtc_en.ini";
                break;
            }
            case "zh": {
                dirDtc = Common.Dir + Common.GuestName + "/" + carType + "/" + "dtc_zh.ini";
                break;
            }case "ru": {
                dirDtc = Common.Dir + Common.GuestName + "/" + carType + "/" + "dtc_ru.ini";
                break;
            }
        }
        return dirDtc;
    }

    public static String getStepFilePath(int stationPosition, String carType) {
        switch (language) {
            case "en": {
                stepFilePath = Common.Dir + Common.GuestName + "/" + carType + "/" + "step_" + stationPosition + "-ru.ini";
                break;
            }
            case "zh": {
                stepFilePath = Common.Dir + Common.GuestName + "/" + carType + "/" + "step_" + stationPosition + ".ini";
                break;
            }case "ru": {
                stepFilePath = Common.Dir + Common.GuestName + "/" + carType + "/" + "step_" + stationPosition + "-ru.ini";
                break;
            }
        }
        return stepFilePath;
    }

    public static String changeConfigFile() {
        String configFile = null;
        switch (Common.Lang) {
            case "en": {
                configFile = Common.Dir + Common.GuestName + "/config-ru.ini";
                break;
            }
            case "ru": {
                configFile = Common.Dir + Common.GuestName + "/config-ru.ini";
                break;
            }
            case "zh": {
                configFile = Common.Dir + Common.GuestName + "/config.ini";
                break;
            }
        }
        return configFile;
    }

}
